'''装饰器

增强函数的功能
'''

import time
from datetime import datetime

def log(func):
    def wrapper(*args, **kwargs):
        print(f'{datetime.now()} call {func.__name__}(): ')

        return func(*args, **kwargs)
    return wrapper


import functools

def log2(func):
    ''' functools 不带参数用法

    :param func:
    :return:
    '''
    @functools.wraps(func)
    def wrapper(*args, **kw):
        print('call %s():' % func.__name__)
        return func(*args, **kw)
    return wrapper

def log3(text):
    '''带参数的装饰器
    :param text:
    :return:
    '''
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kw):
            print('%s %s():' % (text, func.__name__))
            return func(*args, **kw)
        return wrapper
    return decorator

@log
def now():
    print('基础装饰器')

@log2
def now2():
    print(' functools 装饰器')


@log3('测试')
def now3():
    print('functools 传承装饰器')

if __name__ == '__main__':
    now()
    print('-----------------')
    now2()
    print('-----------------')
    now3()
